﻿#region Using Directives

using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Features;

#endregion

namespace FeatureBuilder.ContribLib.Commands
{
    /// <summary>
    /// Starts an external process.
    /// </summary>
    [DisplayName("Start Process")]
    [Description("Starts an external process.")]
    [Category("External")]
    public class StartProcessCommand : FeatureCommand
    {

        public string FileName { get; set; }
        public string Arguments { get; set; }

        /// <summary>
        /// Gets the ServiceProvider that we will use to get a reference to DTE.
        /// </summary>
        [Import(typeof(SVsServiceProvider))]
        public IServiceProvider ServiceProvider { get; private set; }

        /// <summary>
        /// Gets the Feature Extension instance for this invocation
        /// of the Condition
        /// </summary>
        [Import(AllowDefault = true)]
        public IFeatureExtension Feature { get; private set; }

        #region Overrides

        public override void Execute()
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE.DTE;
            if (dte == null)
                return;

            dte.StatusBar.Text = string.Format("Starting process {0} {1}", FileName, Arguments);
            System.Diagnostics.Process.Start(FileName, Arguments);
            dte.StatusBar.Text = "Ready";
        }

        #endregion

    }
}